using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : BattleBase
{
    [SerializeField] private float m_Speed = 5.0f;
    [SerializeField] private bool joystickMode = false;
    private Rigidbody2D rg;
    // Start is called before the first frame update
    void Start()
    {
        rg = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        // CD����
        if (_fireCD > 0.0f)
        {
            _fireCD -= Time.deltaTime;
        }
        else if (Input.GetMouseButtonDown(0))
        {
            // ����
            Fire();
        }
    }

    private void FixedUpdate()
    {
        Vector2 m_Input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
        float rotationAngle = Mathf.Atan2(m_Input.y, m_Input.x) * 180 / Mathf.PI;
        // ��ɫת��
        if (joystickMode)
        // �ֱ�
        {
            if (!m_Input.Equals(Vector2.zero))
                unit.transform.rotation = Quaternion.AngleAxis(rotationAngle, Vector3.forward);
        }
        else
        // ����
        {
            Vector3 direction = Input.mousePosition - Camera.main.WorldToScreenPoint(bulletPoint.transform.position);
            direction.z = unit.transform.position.z;
            direction = direction.normalized;
            unit.transform.up = direction;
        }
        // �ƶ�
        rg.MovePosition(new Vector2(rg.position.x, rg.position.y) + m_Input * Time.deltaTime * m_Speed);

    }
}
